#include "controlbar.h"
#include <QDebug>

ControlBar::ControlBar(QWidget *parent) : QWidget(parent)
{
    timeSlider = new QSlider(this);
    timeSlider->setOrientation(Qt::Horizontal);
    timeSlider->setSingleStep(1);
    timeSlider->setMaximum(200);
    timeLabel = new QLabel("2:37", this);
    StartStopButton = new QPushButton("Start/Stop", this);
    QHBoxLayout* layout = new QHBoxLayout(this);
    layout->addWidget(StartStopButton);
    layout->addWidget(timeSlider);
    layout->addWidget(timeLabel);
    setLayout(layout);

    QObject::connect(timeSlider, SIGNAL(sliderMoved(int)), this, SLOT(onTimeChange(int)));
    QObject::connect(StartStopButton, SIGNAL(clicked()), this, SLOT(resumePause()));
    //QObject::connect(VideoPlayer::get(), SIGNAL(videoTimeChanged(int)), this, SLOT(updateControlBar(int)));
    //QObject::connect(VideoPlayer::get(), SIGNAL(newSongPlaying(int)), this, SLOT(initNewSong(int)));
    //QObject::connect(this, SIGNAL(changeVideoTimeTo(int)), VideoPlayer::get(), SLOT(setTime(int)));
}

void ControlBar::updateControlBar(int newtime)
{
    timeSlider->setValue(newtime);
}

void ControlBar::resumePause()
{

}

void ControlBar::initNewSong(int length)
{
    timeLabel->setText(QString(length));
}

void ControlBar::onTimeChange(int newTime)
{
    emit changeVideoTimeTo(newTime);
}
